<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>添加表格调查项</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layui/css/layui.css">
  <link rel="stylesheet" href="../layui/css/lxq.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="../layui/layui.js" charset="utf-8"></script>
</head>
<body class="layui-layout-body">
<form class="layui-form" style="margin-top: 100px" id="submit1">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <label><input class="layui-btn" type="button" data-method="addInput" value="add"></label>
        </div>
    </div>
    <div  id="hahaha">
        <div class="layui-form-item">
            <label class="layui-form-label">test:</label>
            <div class="layui-input-inline">
                <input type="text" placeholder="请输入标题" class="layui-input">
            </div>
            <input type="button" value="del" data-method="delInput" class="layui-btn">
        </div>
    </div>
</form>

<script src="./layui/layui.js"></script>
<script>
  layui.use('layer', function(){
    var $ = layui.jquery, layer = layui.layer;
    var active = {
      addInput: function () {
            var newInput =
              '<div class="layui-form-item">\n' +
              '\t<label class="layui-form-label">test:</label>\n' +
              '\t<div class="layui-input-inline">\n' +
              '\t\t<input type="text" placeholder="请输入标题" class="layui-input">\n' +
              '\t</div>\n' +
              '\t<input type="button" value="del" data-method="delInput" class="layui-btn">\n'+
              '</div>';
            $('#hahaha').append(newInput);
      },
      delInput: function (othis) {
            othis.parent().remove();
      }
    };
    //已加载完的元素用
    $('.layui-btn').on('click', function () {
        var othis = $(this), method = othis.data('method');
            active[method].call(this, othis);
    });
    //动态加载元素用
    $('#hahaha').on('click','.layui-btn', function () {
        var othis = $(this), method = othis.data('method');
        active[method].call(this, othis);
    });
});
</script>
</body>
</html>